//
//  QPerfectOrderInforMationCell.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/7.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QPerfectOrderInforMationCell.h"


@interface QPerfectOrderInforMationCell()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightConstrain;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineHeight;

@property (weak, nonatomic) IBOutlet UILabel *sendCostlabel;
@end

@implementation QPerfectOrderInforMationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.lineHeight.constant = 0.5;
    [self.textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventEditingChanged];
    self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}

- (void)setShowKeyBoard:(BOOL)showKeyBoard{
    _showKeyBoard = showKeyBoard;
    if(_indexPath.section == 1 && _indexPath.row == 0){
        if(self.showKeyBoard){
            [self.textField becomeFirstResponder];
        }else{
            [self.textField resignFirstResponder];
        }
    }
}

- (void)setIndexPath:(NSIndexPath *)indexPath{
    _indexPath = indexPath;
    if(_indexPath.section == 2 && _indexPath.row == 2){
        [self setSeparatorInset:UIEdgeInsetsMake(0, 85, 0, 0)];
        [self setLayoutMargins:UIEdgeInsetsMake(0, 85, 0, 0)];
    }else{
        [self setSeparatorInset:UIEdgeInsetsZero];
        [self setLayoutMargins:UIEdgeInsetsZero];
    }
    
    if (_indexPath.section == 2) {
       
        self.titleLabel.text = @"加油金额";
        self.textField.hidden = NO;
        self.textField.placeholder = @"国五500元起送,国四1000元起送";
        self.textField.keyboardType = UIKeyboardTypeNumberPad;
        self.subTitleLabel.hidden = YES;
        self.positionBtn.hidden = YES;
        self.positionImageView.hidden = YES;
        self.myPlace.hidden = NO;
        self.rightConstrain.constant = 40;
        self.myPlace.hidden = YES;
        //标题
        self.yTitleMoneyLabel.hidden = YES;
        self.yMoneyLabel.hidden = YES;
        self.yMoneyLabel.text = [NSString stringWithFormat:@"￥%@",[QUserInfo sharedInfo].loginModel.availableBalance];
        self.textField.tag = 1;

    }else if (_indexPath.section == 4 ){
        self.titleLabel.text = @"到达时间";
        self.textField.hidden = YES;
        self.subTitleLabel.hidden = NO;
        self.positionBtn.hidden = YES;
        self.positionImageView.hidden = NO;
        self.rightConstrain.constant = 20;
        self.myPlace.hidden = YES;
        self.yTitleMoneyLabel.hidden = YES;
        self.yMoneyLabel.hidden = YES;
        self.sendCostlabel.hidden = NO;

    }else if (_indexPath.section == 0){

        if (_indexPath.row == 0) {
            self.titleLabel.text = @"加油地点";
            self.textField.hidden = YES;
            self.subTitleLabel.hidden = NO;
            self.positionBtn.hidden = NO;
            self.positionImageView.hidden = NO;
            self.myPlace.hidden = NO;
            self.rightConstrain.constant = 20;
            self.myPlace.text = @"我的位置";
            self.myPlace.textColor = [QColorUtility defaultBackColor];
            self.yTitleMoneyLabel.hidden = YES;
            self.yMoneyLabel.hidden = YES;

        }else if (_indexPath.row == 1){
            
            self.titleLabel.text = @"";
            self.textField.hidden = NO;
            self.textField.keyboardType = UIKeyboardTypeDefault;
            self.subTitleLabel.hidden = YES;
            self.positionBtn.hidden = YES;
            self.positionImageView.hidden = YES;
            self.myPlace.hidden = YES;
            self.rightConstrain.constant = 20;
            self.textField.placeholder = @"手动输入详细地址";
            self.textField.tag = 2;
            self.yTitleMoneyLabel.hidden = YES;
            self.yMoneyLabel.hidden = YES;

        }
    }else if (_indexPath.section == 6){
        
        self.titleLabel.text = @"联系电话";
        self.textField.hidden = NO;
        self.textField.placeholder = @"请填写操作人员电话以便联系";
        self.textField.keyboardType = UIKeyboardTypeNumberPad;
        self.subTitleLabel.hidden = YES;
        self.positionBtn.hidden = YES;
        self.positionImageView.hidden = YES;
        self.myPlace.hidden = YES;
        self.rightConstrain.constant = 20;
        _textField.text = [QUserInfo sharedInfo].loginModel.lastOrderPhone;
        self.textField.tag = 3;
        self.yTitleMoneyLabel.hidden = YES;
        self.yMoneyLabel.hidden = YES;
        self.addressBookbtn.hidden = YES;

    }else if (_indexPath.section == 5){
        self.titleLabel.text = @"联系人";
        self.textField.hidden = NO;
        self.textField.placeholder = @"请填写操作人员姓名";
        self.subTitleLabel.hidden = YES;
        self.positionBtn.hidden = YES;
        self.positionImageView.hidden = YES;
        self.myPlace.hidden = YES;
        self.rightConstrain.constant = 20;
        self.textField.tag = 4;
        self.yTitleMoneyLabel.hidden = YES;
        self.yMoneyLabel.hidden = YES;
        self.addressBookbtn.hidden = NO;


    }
    
//    if(_indexPath.section == 1){
//        self.titleLabel.text = @"加油金额";
//        self.textField.hidden = NO;
//        self.textField.placeholder = @"500元起加";
//        self.textField.keyboardType = UIKeyboardTypeNumberPad;
//        self.subTitleLabel.hidden = YES;
//        self.positionBtn.hidden = YES;
//        self.positionImageView.hidden = YES;
//        self.myPlace.hidden = NO;
//        self.rightConstrain.constant = 40;
//        self.myPlace.hidden = YES;
//        self.yTitleMoneyLabel.hidden = NO;
//        self.yMoneyLabel.hidden = NO;
//        self.yMoneyLabel.text = [NSString stringWithFormat:@"￥%@",[QUserInfo sharedInfo].loginModel.availableBalance];
//        self.textField.tag = 1;
//    }else if (_indexPath.section == 2){
//        if(_indexPath.row == 0){
//            self.titleLabel.text = @"到达时间";
//            self.textField.hidden = YES;
//            self.subTitleLabel.hidden = NO;
//            self.positionBtn.hidden = YES;
//            self.positionImageView.hidden = YES;
//            self.rightConstrain.constant = 20;
//            self.myPlace.hidden = YES;
//            self.yTitleMoneyLabel.hidden = YES;
//            self.yMoneyLabel.hidden = YES;
//        }else if (_indexPath.row == 1){
//            self.titleLabel.text = @"加油地点";
//            self.textField.hidden = YES;
//            self.subTitleLabel.hidden = NO;
//            self.positionBtn.hidden = NO;
//            self.positionImageView.hidden = NO;
//            self.myPlace.hidden = NO;
//            self.rightConstrain.constant = 20;
//            self.myPlace.text = @"我的位置";
//            self.myPlace.textColor = [QColorUtility defaultBackColor];
//            self.yTitleMoneyLabel.hidden = YES;
//            self.yMoneyLabel.hidden = YES;
//        }else if (_indexPath.row == 2){
//            self.titleLabel.text = @"";
//            self.textField.hidden = NO;
//            self.textField.keyboardType = UIKeyboardTypeDefault;
//            self.subTitleLabel.hidden = YES;
//            self.positionBtn.hidden = YES;
//            self.positionImageView.hidden = YES;
//            self.myPlace.hidden = YES;
//            self.rightConstrain.constant = 20;
//            self.textField.tag = 2;
//            self.yTitleMoneyLabel.hidden = YES;
//            self.yMoneyLabel.hidden = YES;
//        }
//    } else if (_indexPath.section == 3){
//        self.titleLabel.text = @"联系电话";
//        self.textField.hidden = NO;
//        self.textField.placeholder = @"请填写操作人员电话以便联系";
//        self.textField.keyboardType = UIKeyboardTypeNumberPad;
//        self.subTitleLabel.hidden = YES;
//        self.positionBtn.hidden = YES;
//        self.positionImageView.hidden = YES;
//        self.myPlace.hidden = YES;
//        self.rightConstrain.constant = 20;
//        _textField.text = [QUserInfo sharedInfo].loginModel.lastOrderPhone;
//        self.textField.tag = 3;
//        self.yTitleMoneyLabel.hidden = YES;
//        self.yMoneyLabel.hidden = YES;
//    }
}

- (void)textFieldAction:(UITextField *)tex{
    if(self.FieldBlock){
        self.FieldBlock(tex.text,tex.tag);
    }
}

- (IBAction)myPlaceBtnAction:(id)sender {
    if(self.PlaceBlock){
        self.PlaceBlock();
    }
}
//通讯录
- (IBAction)addressAction:(id)sender {
    
//    if (self.AddressBookBlock) {
//        self.AddressBookBlock();
//    }
    [self.delegate AddressBookDelegateAction];
}

- (void)setPriceStr:(NSString *)priceStr{

    _priceStr = priceStr;
    if (_indexPath.section == 2 && _indexPath.row == 0){
        self.textField.text = _priceStr?_priceStr:@"";
        if ([_priceStr isEqualToString:@"以实际加油金额为准"]){
            _textField.userInteractionEnabled = NO;
        }else{
            _textField.userInteractionEnabled = YES;
        }
    }
}

- (void)setAddOilTimeStr:(NSString *)addOilTimeStr{

    _addOilTimeStr = addOilTimeStr;
    if (_indexPath.section == 4 && _indexPath.row == 0){
        _subTitleLabel.text = _addOilTimeStr?_addOilTimeStr:@"点击选择加油时间";
    }
}

- (void)setSendCostStr:(NSString *)sendCostStr{
    _sendCostStr = sendCostStr;
    if (_indexPath.section == 4 && _indexPath.row == 0) {
        if (_sendCostStr == nil) {
            _sendCostlabel.hidden = YES;
        }else{
            _sendCostlabel.hidden = NO;
            _sendCostlabel.text = _sendCostStr;
        }
        _sendCostlabel.text = _sendCostStr?_sendCostStr:@"";
    }
}

- (void)setPlaceStr:(NSString *)placeStr{

    _placeStr = placeStr;
    if (_indexPath.section == 0 && _indexPath.row == 0){
        
        _subTitleLabel.text = _placeStr?_placeStr:@"定位到市 区";
    }
}

- (void)setAddressStr:(NSString *)addressStr{

    _addressStr = addressStr;
    if (_indexPath.section == 0 && _indexPath.row == 1){
        self.textField.text = _addressStr?_addressStr:@"手动输入详细地址";
    }
}

- (void)setTelStr:(NSString *)telStr{
    _telStr = telStr;
    if (_indexPath.section == 6 && _indexPath.row == 0){
        self.textField.text = _telStr?_telStr:@"填写操作人员电话";
    }

}

- (void)setNameStr:(NSString *)nameStr{
    _nameStr = nameStr;
    if (_indexPath.section == 5) {
        self.textField.text = _nameStr?_nameStr:@"填写操作人员姓名";

    }
}
- (void)setCellWithData:(NSString *)data{

    if (!([data isEqualToString:@""]||data == nil)) {
        self.textField.placeholder = [NSString stringWithFormat:@"最低加油金额%@",data];//@"国五500元起送,国四1000元起送"        
    }
}

@end
